﻿using System.Collections.Generic;
using DTTB.Assembler.Base;
using DTTB.DAO.Base;

namespace DTTB.SERVICE.Base
{
    public class BaseService<TDto, TEntity> : IBaseService<TDto> //where TEntity : new()
    {
        //public IBaseDao<TEntity> BaseDao { get; set; }
        //public IAssembler<TDto, TEntity> Assembler { get; set; }

        BaseDao<TEntity> BaseDao = new BaseDao<TEntity>();
        public BaseAssembler<TDto,TEntity> Assembler = new BaseAssembler<TDto,TEntity>();
        

        public IList<TDto> GetAllEntities()
        {
            var entities = BaseDao.GetAllEntities();
            return Assembler.ConvertToDataTransferObjectList(entities);
        }

        public IList<TDto> GetAllEntities(string tableName)
        {
            var entities = BaseDao.GetAllEntities(tableName);
            return Assembler.ConvertToDataTransferObjectList(entities);
        }

        public bool AddNewEntity(TDto dto, ref int idReturn)
        {
            return BaseDao.AddNewEntity(Assembler.ConvertToBusinessObject(dto), ref idReturn);
        }
        
        public bool AddNewEntity(TDto dto)
        {
            return BaseDao.AddNewEntity(Assembler.ConvertToBusinessObject(dto));
        }
        
        public bool AddNewEntity(TDto dto, string table, ref int idReturn)
        {
            return BaseDao.AddNewEntity(Assembler.ConvertToBusinessObject(dto), table, ref idReturn);
        }
        
        public bool AddNewEntity(TDto dto, string table)
        {
            return BaseDao.AddNewEntity(Assembler.ConvertToBusinessObject(dto), table);
        }
        
    }
}
